﻿using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Controls;
using System.Windows.Printing;

namespace PrintControl {
    public partial class MsBoxLabel : UserControl {

        public MsBoxLabel() {
            InitializeComponent();
        }
        private void PrintButton_Click(object sender, RoutedEventArgs e) {
            PrintDocument _printDocument = new PrintDocument();

            _printDocument.BeginPrint += (s, ea) => {
                btnPrint.Visibility = System.Windows.Visibility.Collapsed;
            };
            _printDocument.EndPrint += (s, ea) => {
                LayoutRoot.RenderTransform = null; // clear out render transform   
                btnPrint.Visibility = System.Windows.Visibility.Visible;
                //MessageBox.Show("Print job complete.");
            };
            _printDocument.PrintPage += (s, ea) => {
                TransformGroup _transformGroup = new TransformGroup();
                _transformGroup.Children.Add(new ScaleTransform() { ScaleX = 4, ScaleY = 4 });
                _transformGroup.Children.Add(new RotateTransform() { Angle = 90 });
                _transformGroup.Children.Add(new TranslateTransform() { X = 0.7 * ea.PrintableArea.Width, Y = 0.14 * ea.PrintableArea.Height });

                LayoutRoot.RenderTransform = _transformGroup;
                ea.PageVisual = LayoutRoot;
                ea.HasMorePages = false;
            };
            _printDocument.Print("MsBoxLabel"); // print file name
        }

    }
}
